<template>
  <div class="service-card">
    <!-- 卡片顶部图片区域 -->
    <div class="card-image" :style="{ backgroundImage: `url(${service.bgImage})` }">
      <div class="image-content">
        <div class="service-logo">
          <img :src="service.logo" :alt="service.name">
        </div>
        <div class="service-name">{{ service.name }}</div>
      </div>
    </div>

    <!-- 卡片底部信息区域 -->
    <div class="card-info">
      <!-- 标签列表 -->
      <div class="tag-list">
        <span class="tag" v-for="(tag, index) in service.tags" :key="index">
          {{ tag }}
        </span>
      </div>

      <!-- 账号信息 -->
      <div class="account-info">
        <p><strong>账号：</strong>{{ service.account }}</p>
        <p><strong>密码：</strong>{{ service.password }}</p>
      </div>

      <div class="price-info">
        <div class="validity-info">
          <div class="validity-label">有效期至</div>
          <div class="validity-date">{{ formatDate(service.validity) }}</div>
          <div class="validity-status" :class="{ 'is-expired': isExpired }">
            {{ isExpired ? '已过期' : '使用中' }}
          </div>
        </div>
        <button class="access-btn" @click="handleQuickAccess">
          访问官网
          <i class="el-icon-arrow-right"></i>
        </button>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: 'ServiceCard',
  props: {
    service: {
      type: Object,
      required: true
    }
  },
  computed: {
    isExpired() {
      return new Date(this.service.validity) < new Date()
    }
  },
  methods: {
    formatDate(dateString) {
      const date = new Date(dateString)
      return `${date.getFullYear()}年${date.getMonth() + 1}月${date.getDate()}日`
    },
    handleQuickAccess() {
      window.open(this.service.accessUrl, '_blank')
    }
  }
}
</script>

<style scoped>
.service-card {
  position: relative;
  border-radius: 16px;
  overflow: hidden;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.08);
  background: white;
  width: 48%;
  transition: all 0.4s cubic-bezier(0.165, 0.84, 0.44, 1);
}

.service-card:hover {
  transform: scale(1.02);
  box-shadow: 0 8px 30px rgba(63, 93, 98, 0.2);
}

.card-image {
  height: 240px;
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
  position: relative;
  opacity: 0.8;
  transition: opacity 0.3s ease;
}

.service-card:hover .card-image {
  opacity: 0.9;
}

.image-content {
  position: absolute;
  top: 20px;
  left: 20px;
  display: flex;
  align-items: center;
  gap: 12px;
  background: rgba(255, 255, 255, 0.9);
  padding: 8px 16px;
  border-radius: 8px;
}

.service-logo {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  overflow: hidden;
  background: white;
}

.service-logo img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.service-name {
  font-size: 1.1rem;
  font-weight: 500;
  color: #333;
}

.card-info {
  padding: 20px;
  background: white;
}

.tag-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 15px;
}

.tag {
  padding: 6px 15px;
  border-radius: 20px;
  background: rgba(63, 93, 98, 0.1);
  color: #3F5D62;
  font-size: 0.85rem;
  border: 1px solid rgba(63, 93, 98, 0.2);
  transition: all 0.3s;
}

.tag:hover {
  background: rgba(63, 93, 98, 0.2);
  border-color: #3F5D62;
  transform: translateY(-2px);
}

.account-info {
  font-size: 0.9rem;
  color: #666;
  margin-bottom: 15px;
  padding: 10px;
  background: #f8f9fa;
  border-radius: 8px;
}

.account-info p {
  margin: 4px 0;
}

.validity-info {
  display: flex;
  align-items: center;
  gap: 10px;
  background: #F8F9FA;
  padding: 8px 16px;
  border-radius: 20px;
  border: 1px solid rgba(63, 93, 98, 0.1);
}

.validity-label {
  color: #666;
  font-size: 0.9rem;
}

.validity-date {
  color: #333;
  font-weight: 500;
  font-size: 0.9rem;
}

.validity-status {
  padding: 2px 8px;
  border-radius: 12px;
  font-size: 0.8rem;
  background: rgba(82, 196, 26, 0.1);
  color: #52c41a;
}

.validity-status.is-expired {
  background: rgba(245, 34, 45, 0.1);
  color: #f5222d;
}

.price-info {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 15px;
}

.access-btn {
  padding: 8px 24px;
  border: none;
  border-radius: 20px;
  background: linear-gradient(135deg, #3F5D62, #5A8087);
  color: white;
  font-size: 0.95rem;
  cursor: pointer;
  transition: all 0.3s;
  display: flex;
  align-items: center;
  gap: 8px;
  box-shadow: 0 2px 10px rgba(63, 93, 98, 0.2);
}

.access-btn i {
  font-size: 0.9em;
  transition: transform 0.3s;
}

.access-btn:hover {
  box-shadow: 0 4px 15px rgba(63, 93, 98, 0.3);
  transform: translateY(-1px);
}

.access-btn:hover i {
  transform: translateX(3px);
}

.access-btn:active {
  transform: translateY(0);
}

@media (max-width: 768px) {
  .card-image {
    height: 150px;
  }

  .price-info {
    flex-direction: column;
    gap: 15px;
  }

  .validity-info {
    width: 100%;
    justify-content: center;
  }

  .access-btn {
    width: 100%;
    justify-content: center;
  }
}
</style> 